package com.witdata.common.domain.vo;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.witdata.common.domain.dto.CourseDto;
import com.witdata.common.domain.enums.classroom.Term;
import com.witdata.common.serializer.ToLongDeSerializer;
import com.witdata.mysql.domain.entity.TCourses;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor

public class CourseVo {

    @JsonSerialize(using = ToStringSerializer.class)
    @JsonDeserialize(using = ToLongDeSerializer.class)
    private Long id;

    private String name;

    private String code;

    private Integer term;

    private String description;

    private String requirements;

    private String coverImage;

    private String joinCode;

    private Integer maxStudent;

    private String teacherId;

    public CourseVo(TCourses tCourses) {
        this.id = tCourses.getId();
        this.name = tCourses.getName();
        this.code = tCourses.getCode();
        this.term = tCourses.getTerm()?Term.UP.getCode():Term.DOWN.getCode();
        this.description = tCourses.getDescription();
        this.requirements = tCourses.getRequirements();
        this.coverImage = tCourses.getCoverImage();
        this.joinCode = tCourses.getJoinCode();
        this.maxStudent = tCourses.getMaxStudents();
        this.teacherId = tCourses.getCreatorId().toString();
    }

    public CourseVo(CourseDto courseDto) {
        this.id = courseDto.getId();
        this.name = courseDto.getName();
        this.code = courseDto.getCode();
        this.term = courseDto.getTerm().getCode();
        this.description = courseDto.getDescription();
        this.requirements = courseDto.getRequirements();
        this.coverImage = courseDto.getCoverImage();
        this.joinCode = courseDto.getJoinCode();
        this.maxStudent = courseDto.getMaxStudent();
        this.teacherId = courseDto.getCreatorId().toString();
    }
}
